<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mockery\Exception;
use Illuminate\Support\Facades\DB;


class ConnectController extends Controller
{
    protected $ControllerArray=array(
        'U'=>'UserController',
        'C'=>'CaseController',
        'P'=>'PurviewController',
        'E'=>'EditController',
        'G'=>'GatheringController',
        'O'=>'CountController',
        'V'=>'VisaController',
        'S'=>'SystemController',
        'D'=>'DataCenterController',
        'NO'=>'NoticeCenterController',
        'T'=>'GroupController',
        'N'=>'CalendarController',
        'X'=>'IndexCenterController',
        'R'=>'CustomerCenterController',
		'A'=>'ActionCenterController',
        'L'=>'ApprovalCenterController',
        'RC'=>'RecordController'
    );
    public function Connect(Request $request)
    {
//      $a=$request->header('UserToken');
//      print_r($a);

//      $redis = Redis::connection('default');
//      $redis->SET('test',123);
//      echo 'OK';
//      $a=$redis->GET('test');
//      echo $a;
        date_default_timezone_set('Asia/Shanghai');
        $version=$request->header('Ver')?$request->header('Ver'):'v1';
        $controller=$request->header('Con')?$request->header('Con'):'';
        $controller=isset($this->ControllerArray[$controller])?$this->ControllerArray[$controller]:'';
        $function=$request->header('Fun')?$request->header('Fun'):'error';
        $class_name='Http/Controllers';

        if(!empty($version))
        {
            $class_name.='/'.$version;
        }
        $class_name.='/'.$controller;
        if(!file_exists(app_path($class_name.'.php')))
        {
            http_response_code(404);
            exit();
        }
		$class_name=str_replace('/','\\',$class_name);
        $class_name='\App\\'.$class_name;
        $_temp_=new $class_name;
        if(is_callable(array($_temp_,$function)))
        {
            return $_temp_->$function($request);
        }
        else
        {
            http_response_code(405);
            exit();
        }
    }
    public function test()
    {
      
        $a='case_mode_id';
        $a=str_replace('_',' ',$a);
        $a=ucwords($a);
        $a=str_replace(' ','',$a);
        print_r($a);
       // phpinfo();
    }



}